<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>


<div id="ax_form_result">
    <?php // if(isset($error_message)) echo $error_message;  ?>
</div>

<article class="module width_full">
    <form method="POST" id="acx_form"
          action="<?php // echo $question->uid() ? site_url("question/form") : site_url("question/form")     ?>">
        <header>
            <h3>
                <?php // echo $question->username();  ?>
            </h3>
        </header>
        <div class="module_content">
            <input type="hidden" name="uid" id="uid"
                   value="<?php echo (($question->id() != "") ? $question->id() : ""); ?>" />
            <input type="hidden" name="permission" id="permission" value="trumgame" />

            <fieldset style="width: 100%; float: left; margin-right: 1%;">
                <label>Chủ đề</label>                
                <div class="clear" style="padding: 0 10px;">
                    <?php for($i=0; $i< count($topic); $i++){?>
                        <input type="checkbox" name="topic[]" value="<?php echo $topic[$i]->id()?>" <?php if(in_array($topic[$i]->id(), $topicOfQuestion)) echo "checked"?>> <?php echo $topic[$i]->topics()?> <br>
                    <?php } ?>
                </div>
                <br />
            </fieldset>
            
            <fieldset style="width: 100%; float: left; margin-right: 1%;">
                <label>Câu hỏi</label>                
                <textarea rows="4" style="width: 92%;" id="question" name="question" required><?php echo (($question->question() != "") ? $question->question() : ""); ?></textarea>
                <div class="clear"></div>
                <br />
            </fieldset>

            <fieldset style="width: 100%; float: left; margin-right: 1%;">
                <label>Đáp án</label> <br>               
                <table style="width: 70%; float: left; margin: 3%;">
                    <thead>
                        <tr>
                            <th width="15%">Đ/Á đúng</th>
                            <th width="85%">Các lựa chọn</th>                                                                            
                        </tr>
                    </thead>
                    <tbody>
                        <!--Các phương án trả lời-->
                        <?php for($i = 0; $i < 4; $i++) { ?>
                            <tr style="height: 30px">
                                <th><input type="radio" name="correct" value="<?php echo ($i+1)?>" <?php echo (($question->correct() == $i+1) ? "checked" : ""); ?> required="required"></th>
                                <td><input type="text" name="answer<?php echo $i?>" value="<?php echo (($answer[$i] != "") ? $answer[$i] : ""); ?>" required="required"></td>
                            </tr>
                        <?php } ?>
                                                
                    </tbody>
                </table>
                <br />
            </fieldset>           
            <div class="clear"></div>
            <footer>
                <div class="submit_link">
                    <span class="loading">&nbsp;</span> 
                    <select name="hidden">
                        <option value="0"
                                <?php echo ($question->status() == 0) ? 'selected="selected"' : '' ?>>Kích hoạt</option>
                        <option value="1"
                                <?php echo ($question->status() == 1) ? 'selected="selected"' : '' ?>>Ẩn</option>
                    </select> <input type="submit" value="Lưu lại" class="alt_btn"> <input
                        type="reset" value="Nhập lại" onclick="reset_crawler()">
                </div>
            </footer>
        </div>
    </form>       
</article>

<input type="hidden" name="base_url" id="base_url"
       value="<?php echo base_url() ?>" />

<script>
    function addWModeParameter(oembedData) {
        if (oembedData.type == "movie") {
            var code = oembedData.code;
            var wmode = "transparent";
            if (code != null && code.indexOf("wmode") < 0) {
                code = code.replace("<embed ", "<param name=\"wmode\" value=\"" + wmode + "\"></param>\n<embed ");
                code = code.replace("<embed ", "<embed wmode=\"" + wmode + "\"");
            }
            oembedData.code = code;
        }
        $("#oembed_thumbnail_url").val(oembedData.thumbnail_url);
    }

    $(document).ready(function() {
        $(".oembed").oembed(null, { beforeEmbed: addWModeParameter });
    });

    $('#trailer_link').hide();     
        

    //Frame
    function frameUrl()
    {        
        $('#trailer_link').show();
        
        // $('#movie_link').val(document.getElementById('acx_movie_url').value);

        $('#trailer_link').attr('href', document.getElementById('acx_movie_url').value);        
        
        $("#trailer_link").oembed(null,
        {
            embedMethod: "append",
            //	        maxWidth: 300,
            //	        maxHeight: 300,
            vimeo: { autoplay: false},
            afterEmbed: afterEmbed
        });

        $('#trailer_uri').val($('#acx_movie_url').val());
    }

    function afterEmbed(oembedData){        
        if($('#image_profile').val() == ''){
            url = $('#base_url').val() + 'movie/ajax_save_crawl_file';
            $.ajax({
                url: url,
                type: "POST",
                data: { photo_url: oembedData.thumbnail_url }
            }).success(function(json) {                
                result = $(this).children().children('.crawler_result');
                result.html(json.message);
                data = jQuery.parseJSON(json.data);
                if(json.success){
                    $('#thumbnail').attr('src', data.photo_url);
                    $('#acx_thumb_picture_uri').val(data.media_uri);
                }
            });
        }

    }  
        
</script>

